//1.立即支付弹窗
// 获取相关元素
const payButton = document.querySelector('.submit');
const payModal = document.getElementById('payModal');
const closeModal = document.getElementsByClassName('close')[0];
const confirmPayButton = document.getElementById('confirmPay');
const cancelPayButton = document.getElementById('cancelPay');

// 显示模态框
payButton.addEventListener('click', () => {
  payModal.style.display = 'block';
});

// 关闭模态框
closeModal.addEventListener('click', () => {
  payModal.style.display = 'none';
});
cancelPayButton.addEventListener('click', () => {
  payModal.style.display = 'none';
});

// 阻止点击模态框外部时关闭
// window.addEventListener('click', (event) => {
//   if (event.target === payModal) {
//     payModal.style.display = 'none';
//   }
// });

//获取car.html传入的money&total
let payMoney = JSON.parse(localStorage.getItem('money'));
console.log(payMoney);

let html = '';
html += `总商品金额：<span>${payMoney.toFixed(2)}</span>`;
document.querySelector('.msg2').innerHTML = html;

let html1 = '';
html1 += `${payMoney.toFixed(2)}`;
document.querySelector('.price').innerHTML = html1;

let payTotal = JSON.parse(localStorage.getItem('total'));
let html2 = '';
html2 += `${payTotal}`;
document.querySelector('.num').innerHTML = html2;

let html3 = '';
html3 += `<span>${payTotal}</span>&nbsp;件商品`;
document.querySelector('.msg1').innerHTML = html3;

let html4 = '';
html4 = `应付总额：<span>${(payMoney + 6).toFixed(2)}</span>`
document.querySelector('.msg4').innerHTML = html4;

let Money = payMoney + 6
//更新存储
localStorage.setItem('money', JSON.stringify(Money));
localStorage.setItem('total', JSON.stringify(payTotal));


//跳转pay

  // 为“去结算”按钮添加 click 事件监听器
  confirmPayButton.addEventListener('click', () => {
    // 跳转到指定页面
    window.location.href = 'http://127.0.0.1:5501/pay.html';
  });

// 页面跳转
let navLogin = document.querySelector('.nav-login');
let navRegist = document.querySelector('.nav-regist');

navLogin.addEventListener('click',function(){
  window.location.href = '/login.html';
});
navRegist.addEventListener('click',function(){
  window.location.href = '/register.html';
});